Explaining the mysteries of the Perimeter Scan Formula:

QuickJump: Back to Library - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - Bonus
 
One of the most often-misunderstood features of today's cybugs is the use of the perimeter-scan formula (or one of its many variations), so I (James) decided to write this short piece to try to unravel the concept for anyone having difficulties.

Now before you read further, let me just warn you all that this is currently not as useful as it once was. The introduction of cloaking meant that this method could no longer be relied on to detect enemies, and as always, it does not detect any other obstacles like mines or flags.

However, I do think that it still has a part to play where the programmer desperately needs to speed up their cybug.

How it works:

The formula can basically be thought of as a method of calculating the distance between our cybug and the closest (uncloaked) enemy. It doesn't give you the distance in exact numbers of squares, but you will soon learn what the numbers mean.
 
 Each cybug has access to information regarding the enemy's position (#enemy_x and #enemy_y) and its own position (#x_pos and #y_pos).
 

In the diagram, imagine that our cybug is marked in green and the enemy is blue. 'a' is the difference between the y-coordinates of each cybug:
 
  • a = #y_pos - #enemy_y.
  • also, 'b' is the difference between the x-coordinates:
     

  • b = #x_pos - #enemy_x.
  • So if we add these two numbers together, we get a value which gives us an idea of how far the enemy is from our cybug. There is one other complication though - if the value of the enemy's x or y-coordinate is greater than that of our cybug, then the difference will be negative. In many cases where the difference in one direction is large and positive and the difference in the other direction is large and negative, the result of adding these two together will give a small number even though the enemy is nowhere near us.

    To account for this, square each of the differences. This eliminates the problem of negative differences because when you square any number, positive or negative, you always get a positive result.

    Now the formula is: distance = (#x_pos - #enemy_x)2 + (#y_pos - #enemy_y)2.

    The squaring of each of the brackets means that when the enemy is far away, the result can be very large. However, we are normally only going to be interested in when the enemy is quite close, and at these time the numbers are quite manageable.

    The following table lists the result of the calculation in situations when the enemy is quite close to our cybug. We are in the center square (shown as '0' and highlighted in green) and the number in each of the other squares is the result of the calculation for a closest enemy in that position. Makes sense? If not, have a look anyway coz it took ages to calculate :-)

     
    32
    25
    20
    17
    16
    17
    20
    25
    32
    25
    18
    13
    10
    9
    10
    13
    18
    25
    20
    13
    8
    5
    4
    5
    8
    13
    20
    17
    10
    5
    2
    1
    2
    5
    10
    17
    16
    9
    4
    1
    0
    1
    4
    9
    16
    17
    10
    5
    2
    1
    2
    5
    10
    17
    20
    13
    8
    5
    4
    5
    8
    13
    20
    25
    18
    13
    10
    9
    10
    13
    18
    25
    32
    25
    20
    17
    16
    17
    20
    25
    32
     

     From this table, it can be seen that if an enemy is in any of the spaces directly next to our cybug (shown in blue), the result of the calculation will be 1 or 2. Therefore, it has become normal to do the calculation and then check for the result being less than 3. for example:

    For those of you still using the shareware version of the game (and I stronglty advise anybody to register!) the same can be achieved by: Now that I've finished with the explanations, let me again remind you all that this formula only detects uncloaked enemies!! Apart from that, use it wherever you want to save time on a perimeter scan.

    James

    QuickJump: Back to Library - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - Bonus